package org.aristotle.common.response;

import org.aristotle.common.response.result.Result;
import org.aristotle.common.response.result.ResultCode;

public class ResponseEntity<T> {

    /*请求查询成功*/
    public static <T> Result<T> ok(T data) {
        return new Result<T>(ResultCode.QUERY_SUCCESS.getCode(),ResultCode.QUERY_SUCCESS.getMsg(),data);
    }

    /*请求添加成功*/
    public static <T> Result<T> addOk(T data) {
        return new Result<T>(ResultCode.ADD_SUCCESS.getCode(),ResultCode.ADD_SUCCESS.getMsg(),data);
    }

    /*请求修改成功*/
    public static <T> Result<T> updateOk(T data) {
        return new Result<T>(ResultCode.UPDATE_SUCCESS.getCode(),ResultCode.UPDATE_SUCCESS.getMsg(),data);
    }

    /*请求删除成功*/
    public static <T> Result<T> deleteOk(T data) {
        return new Result<T>(ResultCode.DELETE_SUCCESS.getCode(),ResultCode.DELETE_SUCCESS.getMsg(),data);
    }

    /*参数不合法*/
    public static <T> Result<T> badRequest() {
        return new Result<T>(ResultCode.BAD_REQUEST.getCode(),ResultCode.BAD_REQUEST.getMsg(),null);
    }

    /*参数不合法*/
    public static <T> Result<T> badRequest(String msg) {
        return new Result<T>(ResultCode.BAD_REQUEST.getCode(),msg,null);
    }

    /*令牌错误*/
    public static <T> Result<T> unauthorized() {
        return new Result<T>(ResultCode.UNAUTHORIZED.getCode(),ResultCode.UNAUTHORIZED.getMsg(),null);
    }

    /*权限不足*/
    public static <T> Result<T> forbidden() {
        return new Result<T>(ResultCode.FORBIDDEN.getCode(),ResultCode.FORBIDDEN.getMsg(),null);
    }

    /*访问资源不存在*/
    public static <T> Result<T> notFound() {
        return new Result<T>(ResultCode.NOT_FOUND.getCode(),ResultCode.NOT_FOUND.getMsg(),null);
    }

    /*服务器异常*/
    public static <T> Result<T> error() {
        return new Result<T>(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMsg(),null);
    }

    public static <T> Result<T> failed(ResultCode resultCode) {
        return new Result<T>(resultCode.getCode(), resultCode.getMsg(), null);
    }

}
